from open_ai_model import getOpenAiModel
import asyncio


async def task1():
    model = getOpenAiModel()
    chunks = []
    for chunk in model.stream("天空是什么颜色？"):
        chunks.append(chunk.content)
        print(chunk.content, end="|", flush=True)


async def task2():
    model = getOpenAiModel()
    chunks = []
    for chunk in model.stream("讲个笑话？"):
        chunks.append(chunk.content)
        print(chunk.content, end="|", flush=True)


# 同步调用
async def main():
    await task1()
    await task2()


# asyncio.run(main())


# 异步调用
async def main1():
    await asyncio.gather(task1(), task2())


asyncio.run(main1())
